package com.ailatrieuphu.util;



import android.content.Context;
import android.content.SharedPreferences;

/**
 * Put and get any thing into preference
 * Create by Jack Le
 * Date 15/10/2012
 * */

public class PreferenceUtils {
	
	public static void putString(Context context, String name, String value,
			String key) {
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public static String getString(Context context, String name, String key) {
		String result = null;
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		result = settings.getString(key, null);
		return result;
	}

	public static void putLong(Context context, String name, long value,
			String key) {
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putLong(key, value);
		editor.commit();
	}

	public static long getLong(Context context, String name, String key) {
		long result;
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		result = settings.getLong(key, 0);
		return result;
	}

	public static void putInt(Context context, String name, int value,
			String key) {
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putInt(key, value);
		editor.commit();
	}
	

	public static int getInt(Context context, String name, String key) {
		int result;
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		result = settings.getInt(key, 0);
		return result;
	}
	
	public static void putBoolean(Context context, String name, Boolean value,
			String key) {
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}
	
	

	public static Boolean getBoolean(Context context, String name, String key) {
		Boolean result;
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		result = settings.getBoolean(key, true);
		return result;
	}
	
	public static int getInt(Context context, String name, String key, int defaultValue) {
		int result;
		SharedPreferences settings = context.getSharedPreferences(name, /* MODE_PRIVATE */
				0);
		result = settings.getInt(key, defaultValue);
		return result;
	}
	
//	/* USER NAME */
//	public static void putUsername(Context context, String username) {
//		putString(context, Constant.Preference_Name, username,
//				Constant.Pref_Username);
//	}
//
//	public static String getUsername(Context context) {
//		return getString(context, Constant.Preference_Name,
//				Constant.Pref_Username);
//	}
//	
//	/* PASSWORD */
//	public static void putPassword(Context context, String password) {
//		putString(context, Constant.Preference_Name, password,
//				Constant.Pref_Password);
//	}
//	
//	public static String getPassword(Context context) {
//		return getString(context, Constant.Preference_Name,
//				Constant.Pref_Password);
//	}
//	
//	/* STATUS BAR HEIGHT */
//	public static void putStatuBarHeight(Context context, int height) {
//		putInt(context, Constant.Preference_Name, height, Constant.Preference_StatusBarHeight);
//	}
//	
//	public static int getStatusBarHeight(Context context) {
//		return getInt(context, Constant.Preference_Name, Constant.Preference_StatusBarHeight);
//	}
//	
//
//	/* TOKEN KEY */
//	public static void putTokenKey(Context context, String tokenKey) {
//		putString(context, Constant.Preference_Name, tokenKey,
//				Constant.Pref_Token);
//	}
//
//	public static String getTokenkey(Context context) {
//		return getString(context, Constant.Preference_Name,
//				Constant.Pref_Token);
//	}
//	
//	/* APPRAISAL ID */
//	public static void putAppraisalId(Context context, String appraisalId) {
//		putString(context, Constant.Preference_Name, appraisalId,
//				Constant.Pref_APPRAISAL_ID);
//	}
//
//	public static String getAppraisalId(Context context) {
//		return getString(context, Constant.Preference_Name,
//				Constant.Pref_APPRAISAL_ID);
//	}
//	
//	/* alternative password */
//	public static void putAltenativePassword(Context context, String password) {
//		putString(context, Constant.Preference_Name, password,
//				Constant.Pres_ALERTENATIVE_PASSWORD);
//	}
//
//	public static String getAlertenativePassword(Context context) {
//		return getString(context, Constant.Preference_Name,
//				Constant.Pres_ALERTENATIVE_PASSWORD);
//	}
}
